package com.yun.algorithmproblem.leetcode;

public class Leetcode2412 {

    public long minimumMoney(int[][] transactions) {
        int loseMax = 0;
        int makeMax = 0;
        int totalLose = 0;
        for (int[] t : transactions) {
            if (t[0] >= t[1]) {
                loseMax = Math.max(loseMax, t[0]);
                totalLose += t[0] - t[1];
            } else {
                makeMax = Math.max(makeMax, t[0]);
            }
        }
        return Math.max(makeMax + totalLose,loseMax);
    }
}
